home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: more problems with qsort
- Date: 03 Mar 1996 06:16:49 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Mar2231649@qcd.lanl.gov>
- References: <177399702S86.JW1675A@american.edu> <4h0j9e$ng5@clarknet.clark.net>
- <4h81m0$avr@solutions.solon.com> <4hba5n$2ga@clarknet.clark.net>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: yom@clark.net's message of 3 Mar 1996 05:19:51 GMT
-
- In article <4hba5n$2ga@clarknet.clark.net>
- yom@clark.net (yom) writes:
- <snip>
- y: >
- y: >>And your compare function must be defined like this:
- y: >
- y: >>int compare(char **a,char **b) {return strcmp(*a,*b);}
- y: >
- y: >No, it really mustn't. It must be defined like this:
- y: >int compare(const void *a, const void *b) {
- y: > return strcmp(*(char **) a, *(char **) b);
- y: >}
- y:
- y: Well I disagree on this one. Results of 1) defining the compare
- y: function that takes two char** arguments and casting the function call
- y: to qsort and 2) defining the compare function that takes two void*
- y: arguments and casting the arguments to char ** in strcmp call are
- y: identical. Also, I tend to not use "const" because some compilers do
- y: not support it.
-
- You may disagree, but you will be incorrect. char** and const void*
- need not even be of the same size, far less have the same
- representation. If the representation/size differs, the cast will do
- the conversion. Casting the function type just shuts up the compiler.
-
- Also, the current C language defines const: and it requires its use in
- some places. Learn to use it, and if you are worried about pre-ANSI
- compilers, just ifdef things out.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-